package com.elitel.frame.base.service.impl;

import com.elitel.frame.base.service.BaseFieldenumService;
import com.elitel.frame.main.dao.BaseFieldenumMapper;
import com.elitel.frame.main.dao.ext.ExtBaseFieldenumMapper;
import com.elitel.frame.main.dao.ext.ExtCfgFieldMapper;
import com.elitel.frame.main.entity.BaseFieldenum;
import com.elitel.frame.main.entity.CfgField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @description 字段枚举服务接口实现类
 * @author guoyanfei
 * @date 2017/11/28
 */
@Service
public class BaseFieldenumServiceImpl implements BaseFieldenumService {
	@Autowired
	private ExtBaseFieldenumMapper extBaseFieldenumMapper;
	@Autowired
	private BaseFieldenumMapper baseFieldenumMapper;
	@Autowired
	private ExtCfgFieldMapper extCfgFieldMapper;
	
	@Override
	public List<BaseFieldenum> getBaseFieldenumList(String dtConfigId) {
		return extBaseFieldenumMapper.getListbydtConfigId(dtConfigId);
	}

	@Override
	public Integer insertBatchBaseFieldenum(BaseFieldenum baseFieldenum) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Integer result = 0;
		baseFieldenum.setGuid(UUID.randomUUID().toString());
		baseFieldenum.setCreatedate(new Date());
		baseFieldenum.setFieldtype("string");
		result = baseFieldenumMapper.insertSelective(baseFieldenum);
		return result;
	}

	@Override
	public Integer updateBaseFieldenum(BaseFieldenum baseFieldenum) {
		//查询字段类型
		CfgField cfgField = extCfgFieldMapper.selectFieldInfo(baseFieldenum.getDtConfigId(),baseFieldenum.getFieldname());
		if(cfgField != null){
			baseFieldenum.setFieldtype(cfgField.getDtType());
		}
		return baseFieldenumMapper.updateByPrimaryKeySelective(baseFieldenum);
	}

	@Override
	public Integer deleteBatchBaseFieldenum(String guids) {
		Integer result =0;
		String[] guid = guids.split(",");
		for (String str : guid) {
			result += baseFieldenumMapper.deleteByPrimaryKey(str);
		}
		return result;
	}

	@Override
	public BaseFieldenum getBaseFieldenumByguid(String guid) {
		return baseFieldenumMapper.selectByPrimaryKey(guid);
	}
	
	

}
